import flash.events.Event;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Matrix;
import flash.text.TextField;
import flash.text.TextFormat;

import Images;
class AchievementPageEvent extends Event{
 
	public function new(customEventString:String){

	super(customEventString, true, false);

    }
}

class AchievementPage extends Sprite
{
private var BackButton:Sprite;
private var CurrentBackground: Sprite;
private var Text:TextField;
  public var SmallFortune : PermanentAchievementBox;
  public var Fortune : PermanentAchievementBox;
  public var SmallCountry : PermanentAchievementBox;

  public var KindHearted : PermanentAchievementBox;
  public var DecreasedWorldSuck : PermanentAchievementBox;
  public var SaveTheWorld : PermanentAchievementBox;

  public var PerfectPair : PermanentAchievementBox;
  public var MoreThanBalance : PermanentAchievementBox;

  public var RecievedAchievements:Achievements; 

  public function new(inAchievements:Achievements)
  {
  super();
  //Resize Image
  RecievedAchievements = inAchievements;
  SmallFortune = new PermanentAchievementBox("SmallFortune");
  SmallFortune.x = 5; SmallFortune.y = 105;
  SmallFortune.text.htmlText = "<font color='#FFFFFF'>Have $10 Million+ in Cash.</font>";
  SmallFortune.title.htmlText = "<font size = '14' color='#FFFFFF'> Small Fortune</font>";
  SmallFortune.Icon.graphics.beginBitmapFill(new Money1());
  SmallFortune.Icon.graphics.drawRect(0, 0, 50 ,50);

  Fortune = new PermanentAchievementBox("Fortune");
  Fortune.x = 5; Fortune.y = 210;
  Fortune.text.htmlText = "<font color='#FFFFFF'>Have $500 Million+ in Cash.</font>";
  Fortune.title.htmlText = "<font size = '14' color='#FFFFFF'> Fortune</font>";
  Fortune.Icon.graphics.beginBitmapFill(new Money2());
  Fortune.Icon.graphics.drawRect(0, 0, 50 ,50);

  SmallCountry = new PermanentAchievementBox("SmallCountry");
  SmallCountry.x = 5; SmallCountry.y = 315;
  SmallCountry.text.htmlText = "<font color='#FFFFFF'>Have $3 Billion+ in Cash.</font>";
  SmallCountry.title.htmlText = "<font size = '14' color='#FFFFFF'> Small Country</font>";
  SmallCountry.Icon.graphics.beginBitmapFill(new Money3());
  SmallCountry.Icon.graphics.drawRect(0, 0, 50 ,50);

  KindHearted = new PermanentAchievementBox("KindHearted");
  KindHearted.x = 425; KindHearted.y = 105;
  KindHearted.text.htmlText = "<font color='#000000'>Help 100,000 People.</font>";
  KindHearted.title.htmlText = "<font size = '14' color='#000000'> Kind Hearted</font>";
  KindHearted.TextBackground.graphics.clear();
  KindHearted.TextBackground.graphics.beginFill(0xFFFFFF);
  KindHearted.TextBackground.graphics.lineStyle(1,0x000000);
  KindHearted.TextBackground.graphics.drawRect(0, 0, 205, 100);
  KindHearted.Icon.graphics.clear();
  KindHearted.Icon.graphics.beginFill(0xFFFFFF);
  KindHearted.Icon.graphics.lineStyle(1,0x000000);
  KindHearted.Icon.graphics.drawRect(0, 0, 50, 50);
  KindHearted.Icon.graphics.beginBitmapFill(new Heart1());
  KindHearted.Icon.graphics.drawRect(0, 0, 50 ,50);

  DecreasedWorldSuck = new PermanentAchievementBox("DecreasedWorldSuck");
  DecreasedWorldSuck.x = 425; DecreasedWorldSuck.y = 210;
  DecreasedWorldSuck.text.htmlText = "<font color='#000000'>Help 10 million People</font>";
  DecreasedWorldSuck.title.htmlText = "<font size = '14' color='#000000'> Decreased World Suck</font>";
  DecreasedWorldSuck.TextBackground.graphics.clear();
  DecreasedWorldSuck.TextBackground.graphics.beginFill(0xFFFFFF);
  DecreasedWorldSuck.TextBackground.graphics.lineStyle(1,0x000000);
  DecreasedWorldSuck.TextBackground.graphics.drawRect(0, 0, 205, 100);
  DecreasedWorldSuck.Icon.graphics.clear();
  DecreasedWorldSuck.Icon.graphics.beginFill(0xFFFFFF);
  DecreasedWorldSuck.Icon.graphics.lineStyle(1,0x000000);
  DecreasedWorldSuck.Icon.graphics.drawRect(0, 0, 50, 50);
  DecreasedWorldSuck.Icon.graphics.beginBitmapFill(new Heart2());
  DecreasedWorldSuck.Icon.graphics.drawRect(0, 0, 50 ,50);

  SaveTheWorld = new PermanentAchievementBox("SaveTheWorld");
  SaveTheWorld.x = 425; SaveTheWorld.y = 315;
  SaveTheWorld.text.htmlText = "<font color='#000000'>Help 300 Million People.</font>";
  SaveTheWorld.title.htmlText = "<font size = '14' color='#000000'> Save The World</font>";
  SaveTheWorld.TextBackground.graphics.clear();
  SaveTheWorld.TextBackground.graphics.beginFill(0xFFFFFF);
  SaveTheWorld.TextBackground.graphics.lineStyle(1,0x000000);
  SaveTheWorld.TextBackground.graphics.drawRect(0, 0, 205, 100);
  SaveTheWorld.Icon.graphics.clear();
  SaveTheWorld.Icon.graphics.beginFill(0xFFFFFF);
  SaveTheWorld.Icon.graphics.lineStyle(1,0x000000);
  SaveTheWorld.Icon.graphics.drawRect(0, 0, 50, 50);
  SaveTheWorld.Icon.graphics.beginBitmapFill(new Heart3());
  SaveTheWorld.Icon.graphics.drawRect(0, 0, 50 ,50);

  PerfectPair = new PermanentAchievementBox("PerfectPair");
  PerfectPair.x = 215; PerfectPair.y = 155;
  PerfectPair.text.htmlText = "<font color='#FFFFFF'>Help 300 million people and have 3 Billion+ in cash in the same game.</font>";
  PerfectPair.title.htmlText = "<font size = '14' color='#000000'> Perfect Pair</font>";
  PerfectPair.TextBackground.graphics.clear();
  PerfectPair.TextBackground.graphics.beginFill(0xFFFFFF);
  PerfectPair.TextBackground.graphics.lineStyle(1,0x000000);
  PerfectPair.TextBackground.graphics.drawRect(0, 0, 205, 50);
  PerfectPair.TextBackground.graphics.beginFill(0x000000);
  PerfectPair.TextBackground.graphics.lineStyle(1,0xFFFFFF);
  PerfectPair.TextBackground.graphics.drawRect(0, 50, 205, 50);
  PerfectPair.Icon.graphics.clear();
  PerfectPair.Icon.graphics.beginFill(0xFFFFFF);
  PerfectPair.Icon.graphics.lineStyle(1,0x000000);
  PerfectPair.Icon.graphics.drawRect(0, 0, 50, 50);
  PerfectPair.Icon.graphics.beginBitmapFill(new Balance2());
  PerfectPair.Icon.graphics.drawRect(0, 0, 50 ,50);

  MoreThanBalance = new PermanentAchievementBox("MoreThanBalance");
  MoreThanBalance.x = 215; MoreThanBalance.y = 260;
  MoreThanBalance.text.htmlText = "<font color='#FFFFFF'>Recieve a balance of 0.5 on the last turn. Hint: This is super easy.</font>";
  MoreThanBalance.title.htmlText = "<font size = '14' color='#000000'> More Than Balance</font>";
  MoreThanBalance.TextBackground.graphics.clear();
  MoreThanBalance.TextBackground.graphics.beginFill(0xFFFFFF);
  MoreThanBalance.TextBackground.graphics.lineStyle(1,0x000000);
  MoreThanBalance.TextBackground.graphics.drawRect(0, 0, 205, 50);
  MoreThanBalance.TextBackground.graphics.beginFill(0x000000);
  MoreThanBalance.TextBackground.graphics.lineStyle(1,0xFFFFFF);
  MoreThanBalance.TextBackground.graphics.drawRect(0, 50, 205, 50);
  MoreThanBalance.Icon.graphics.clear();
  MoreThanBalance.Icon.graphics.beginFill(0xFFFFFF);
  MoreThanBalance.Icon.graphics.lineStyle(1,0x000000);
  MoreThanBalance.Icon.graphics.drawRect(0, 0, 50, 50);
  MoreThanBalance.Icon.graphics.beginBitmapFill(new Balance1());
  MoreThanBalance.Icon.graphics.drawRect(0, 0, 50 ,50);

  CurrentBackground = new Sprite();//, PixelSnapping.NEVER, true);
  CurrentBackground.graphics.beginFill(0x000000);
  CurrentBackground.graphics.lineStyle(1,0xFFFFFF);
  CurrentBackground.graphics.drawRect(0, 0, Constants.flashWidth,Constants.flashHeight); 
  //End Resize
  addChild(CurrentBackground);

  Text = new TextField();
    
  Text.x = 260; Text.y = 40;
  Text.width = 540; Text.height = 420;
  addChild(Text);
  Text.multiline = true;
  var myFormat:TextFormat = new TextFormat();
  myFormat.size = 15;
  //myFormat.align = TextFormatAlign.CENTER;
  Text.defaultTextFormat = myFormat;
  
  Text.htmlText = "<font color='#FFFFFF' size ='20'><u>Achievements</u></font>";

  BackButton  = new Sprite();
  BackButton.graphics.beginBitmapFill(new BackImage());
  BackButton.graphics.drawRect(0, 0, 25 ,25);
  BackButton.x = 515;
  BackButton.y = 25;
  BackButton.buttonMode = true;
  BackButton.addEventListener(MouseEvent.CLICK, onBackButtonClick);
  addChild(BackButton);

  addChild(SmallCountry);
  addChild(Fortune);
  addChild(SmallFortune);

  addChild(KindHearted);
  addChild(DecreasedWorldSuck);
  addChild(SaveTheWorld);
  
  addChild(PerfectPair);
  addChild(MoreThanBalance);
  redraw();
  }

public function redraw()
{
  SmallFortune.Icon.graphics.clear();
  SmallFortune.Icon.graphics.beginFill(0x000000);
  SmallFortune.Icon.graphics.lineStyle(1,0xFFFFFF);
  if(RecievedAchievements.SmallFortune)
  {
    SmallFortune.Icon.graphics.beginBitmapFill(new Money1());
  }	
  SmallFortune.Icon.graphics.drawRect(0, 0, 50 ,50);

  Fortune.Icon.graphics.clear();
  Fortune.Icon.graphics.beginFill(0x000000);
  Fortune.Icon.graphics.lineStyle(1,0xFFFFFF);
  if(RecievedAchievements.Fortune)
  {
    Fortune.Icon.graphics.beginBitmapFill(new Money2());
  }
  Fortune.Icon.graphics.drawRect(0, 0, 50 ,50);

  SmallCountry.Icon.graphics.clear();
  SmallCountry.Icon.graphics.beginFill(0x000000);
  SmallCountry.Icon.graphics.lineStyle(1,0xFFFFFF);
  SmallCountry.Icon.graphics.drawRect(0, 0, 50, 50);
  if(RecievedAchievements.SmallCountry)
  {
    SmallCountry.Icon.graphics.beginBitmapFill(new Money3());
  }
  SmallCountry.Icon.graphics.drawRect(0, 0, 50 ,50);

  KindHearted.Icon.graphics.clear();
  KindHearted.Icon.graphics.beginFill(0xFFFFFF);
  KindHearted.Icon.graphics.lineStyle(1,0x000000);
  KindHearted.Icon.graphics.drawRect(0, 0, 50, 50);
  if(RecievedAchievements.KindHearted)
  {
    KindHearted.Icon.graphics.beginBitmapFill(new Heart1());
  }
  KindHearted.Icon.graphics.drawRect(0, 0, 50 ,50);

  DecreasedWorldSuck.Icon.graphics.clear();
  DecreasedWorldSuck.Icon.graphics.beginFill(0xFFFFFF);
  DecreasedWorldSuck.Icon.graphics.lineStyle(1,0x000000);
  DecreasedWorldSuck.Icon.graphics.drawRect(0, 0, 50, 50);
  if(RecievedAchievements.DecreasedWorldSuck)
  {
    DecreasedWorldSuck.Icon.graphics.beginBitmapFill(new Heart2());
  }
  DecreasedWorldSuck.Icon.graphics.drawRect(0, 0, 50 ,50);

  SaveTheWorld.Icon.graphics.clear();
  SaveTheWorld.Icon.graphics.beginFill(0xFFFFFF);
  SaveTheWorld.Icon.graphics.lineStyle(1,0x000000);
  SaveTheWorld.Icon.graphics.drawRect(0, 0, 50, 50);
  if(RecievedAchievements.SaveTheWorld)
  {
    SaveTheWorld.Icon.graphics.beginBitmapFill(new Heart3());
  }
  SaveTheWorld.Icon.graphics.drawRect(0, 0, 50 ,50);

  PerfectPair.Icon.graphics.clear();
  PerfectPair.Icon.graphics.beginFill(0xFFFFFF);
  PerfectPair.Icon.graphics.lineStyle(1,0x000000);
  PerfectPair.Icon.graphics.drawRect(0, 0, 50, 50);
  if(RecievedAchievements.PerfectPair)
  {
    PerfectPair.Icon.graphics.beginBitmapFill(new Balance2());
  }
  PerfectPair.Icon.graphics.drawRect(0, 0, 50 ,50);

  MoreThanBalance.Icon.graphics.clear();
  MoreThanBalance.Icon.graphics.beginFill(0xFFFFFF);
  MoreThanBalance.Icon.graphics.lineStyle(1,0x000000);
  MoreThanBalance.Icon.graphics.drawRect(0, 0, 50, 50);
  if(RecievedAchievements.MoreThanBalance)
  {
    MoreThanBalance.Icon.graphics.beginBitmapFill(new Balance1());
  }
  MoreThanBalance.Icon.graphics.drawRect(0, 0, 50 ,50);

}

private function onBackButtonClick(event:MouseEvent) {
    Back();
}

  public function Back()
  {
    dispatchEvent(new AchievementPageEvent("Back"));
  }
}